
<form class="layui-form seller-form" action="">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this"><a href="{:url('userSort')}">钱包日志查询</a></li>
            <li><a href="{:url('userTran')}">消费日志(银12)</a></li>
            <li><a href="{:url('userTranDiff')}">消费日志(银3)</a></li>
            <li><a href="{:url('userUpdate')}">Flag(N=>X)</a></li>
            <li><a href="{:url('xfCardAmount')}">重查卡余额</a></li>
            <li><a href="{:url('addCashError')}">用户余额错误手动添加</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline seller-inline-3" style="width: 300px;">
                        <input type="text" name="user_name" id="user_name" lay-verify="title" placeholder="User Name" autocomplete="off"
                               class="layui-input" >
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i class="iconfont icon-chaxun"></i>Search</button>
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user_cash">修复钱包</button>
                    </div>
                </div>
            </div>
            <div class="table-body">
                <table id="balanceTable" lay-filter="balanceTable"></table>
            </div>
        </div>
    </div>
</form>

<script>
    layui.use(['form', 'table', 'element'], function () {
        layui.table.render({
            elem: '#balanceTable',
            height: 'full-99',
            cellMinWidth: '80',
            totalRow: true,
            method: 'post',
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['exports'],
            url: "{:url('userSort')}",
            id: 'balanceTable',
            cols: [[
                { type: 'numbers'},
                { field: '', align: 'center', title: 'Type' ,width:150,
                    templet: function (d) {
                        const type_name = d.type;
                        if(type_name == 1){
                            return '<font color="red">Debit</font>';
                        }else{
                            return '<font color="green">Credit</font>';
                        }
                    }
                },
                { field: 'amount', align: 'right' ,title: 'Amount($)', width:200 ,totalRow: true},
                { field: 'balance', align: 'right' ,title: 'Balance($)', width:200 },
                { field: 'desc', align: 'left', title: 'Desc' , width:250},
                { align: 'center', title: 'ctime',width:200,
                    templet: function (d) {
                        return layui.util.toDateString(d.ctime * 1000, "yyyy-MM-dd HH:mm:ss");
                    }
                }
            ]],
            page: true,
            limit: 10000,
            limits: [10000],
        });

        layui.form.on('submit(*)', function (data) {
            layui.table.reload('balanceTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        layui.form.on('submit(user_cash)', function () {
            var loading =layer.load(1, {shade: [0.1,'#fff']});
            JsPost("{:url('updateUserCash')}",{username:$("#user_name").val()}, function(res){
                layer.close(loading);
                if(res.code >0){
                    $('#up_time').text(res.data.time);
                    layer.msg(res.msg, { time: 1500 , icon:1}, function () {
                        tableIn.reload({
                            page:{
                                curr :1
                            }
                        });
                    });
                }else{
                    layer.msg(res.msg , {time:1500 , icon:2});
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>